package transformation;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * @author DCSGO
 * @version 1.0
 * OutputStreamWriter 指定保存数据的编码
 */
public class OutputStreamWriter_ {
    public static void main(String[] args) throws IOException {
        String charSetName = "GBK";
        String filePath = "C:\\Users\\Administrator\\Desktop\\Javacode\\java-learning-code\\chapter19\\src\\transformation\\file.txt";
        //将字节流包装成字符流并指定编码为 GBK
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(filePath), charSetName);
        osw.write("你好 Java");
        osw.close();
        System.out.println("按照 " + charSetName + " 编码方式保存数据成功");
    }
}
